#ifndef WARPER_H_
#define WARPER_H_

#include <boost/noncopyable.hpp>

#include "Mutex.h"
#include "AppliedWarp.h"

class Interpolator;
class SimpleImage;

// Describes a thread-safe once-off image warper.
class Warper : private boost::noncopyable {
  public:
    Warper(const AppliedWarp& warp, const Interpolator& interpolator,
        SimpleImage* output);

    // Executes warp and returns the output image.
    void warp();
    // Returns a number in [0, 1] representing percent complete.
    double progress() const;
    // Returns true if a warp has finished.
    bool finished() const;

  private:
    // Input image and warp specifications.
    const AppliedWarp warp_;
    // Interpolation method to use.
    const Interpolator* interpolator_;
    // Output image.
    SimpleImage* output_;
    // How many pixels are in the output image?
    int total_;
    // How much of the warp has been completed (in pixels)?
    int progress_;

    // Mutex on accessing the output image.
    mutable Mutex output_mutex_;
    // Mutex on accessing the progress variables.
    mutable Mutex progress_mutex_;
    // ALWAYS LOCK output_mutex_ BEFORE progress_mutex_ IF BOTH NEEDED!

    Color pixel(int i, int j) const;
};

#endif

